<div class="tab-pane container padding-zero-left" id="learn">
    <section id="purchage-class">
        <div class="row"><!--row 1 ends-->
            <h1>purchased classes</h1>
            <?php
            $this->widget('zii.widgets.CListView', array(
                'dataProvider' => $purchaseClassCourse,
                'summaryText' => '',
                'itemView' => '_purachseClassCourse',
            ));
            ?>


        </div><!--row 1 ends-->
    </section>
    <!--queries made section staris-->
    <section id="queries-made">
        <hr class="queryhr">
        <div class="row"><!--row 1 ends-->
            <h1>Queries made</h1>
            <?php
            $this->widget('zii.widgets.CListView', array(
                'dataProvider' => $dataProvider,
                'summaryText' => '',
                'itemView' => '_learnClassesCourses',
            ));
            ?>
        </div><!--row 1 ends-->
    </section>
    <!--queries made section ends-->
</div>


<script>
    function purachgeClassTrainerReview(id) {
        $('.purchageUserClass').hide();
        $("#purchage-class_" + id).show("slow", function() {
        });
    }
    function puracheClassReview(id) {
        $('.purchageUserClass').hide();
        $("#purchage-class_review_" + id).show("slow", function() {
        });
    }
    function purachgeClassReviewValidate(id, classCourseId, workShopType) {
        var userTextforTrainer = $("#purchage-class_reviewtext_" + id).val();
        var loaderId = 'loaderpurchage_class_review_' + id;
        var manDivId = "purchage-class_" + id;
        var successMessageId = 'successpurchage_class_review_' + id;
        if (userTextforTrainer == '') {
            $("#purchage-class_review_error_" + id).text('Message  can not blank.')
            return false;
        } else {
            $("#purchage-class_review_error_" + id).text('')
            reviewCourseClasses(manDivId, userTextforTrainer, classCourseId, workShopType, loaderId, successMessageId);
        }
    }

    function purachgeClassTrainerValidate(id, userId, userType) {
        var userTextforTrainer = $("#purchage-class_trainer_reviewtext_" + id).val();
        var loaderId = 'loaderpurchage_review_' + id;
        var manDivId = "purchage-class_" + id;
        var successMessageId = 'successpurchage_review_' + id;
        if (userTextforTrainer == '') {
            $("#purchage-class_trainer_error_" + id).text('Message  can not blank.')
            return false;
        } else {
            $("#purchage-class_trainer_error_" + id).text('')
            postReviewtoTrainer(manDivId, userTextforTrainer, userId, userType, loaderId, successMessageId)
        }
    }

    function postReviewtoTrainer(manDivId, userTextforTrainer, userId, userType, loaderId, successMessageId) {
        jQuery.ajax({
            'type': 'POST',
            'url': "<?php echo Yii::app()->createUrl("TrainerProfileReview/create"); ?>",
            'data': 'YII_CSRF_TOKEN=' + $('input[name="YII_CSRF_TOKEN"]').val()+"&text=" + userTextforTrainer + "&userId=" + userId + "&userType=" + userType,
            'beforeSend': function(jqXHR, settings) {
                $("#" + loaderId).show();
            },
            'success': function(data) {
                $("#" + loaderId).hide();
                if (data != "redirect" && data != 'fail') {
                    $("#" + successMessageId).html(data);
                    $('#' + manDivId).delay(1000).fadeOut(1000);

                }
            },
            'cache': false
        });
    }
    function reviewCourseClasses(manDivId, userTextforTrainer, classCourseId, workShopType, loaderId, successMessageId) {
        jQuery.ajax({
            'type': 'POST',
            'url': "<?php echo Yii::app()->createAbsoluteUrl("Reviews/create"); ?>",
            'data': 'YII_CSRF_TOKEN=' + $('input[name="YII_CSRF_TOKEN"]').val()+"&text=" + userTextforTrainer + "&" + workShopType + "=" + classCourseId,
            'beforeSend': function(jqXHR, settings) {
                $("#" + loaderId).show();
            },
            'success': function(data) {
                $("#" + loaderId).hide();
                if (data != "redirect") {
                    $("#" + successMessageId).html(data);
                    $('#' + manDivId).delay(1000).fadeOut(1000);
                }
            },
            'cache': false
        });
    }
    function onclickRateToClass(id, classcoursId, type) {
        var userRate = $("#" + id).val();
        array = id.split('_');
        jQuery.ajax({
            'type': 'POST',
            'url': "<?php echo Yii::app()->createUrl("ClassCourseTrainnerRate/classCourseRate"); ?>",
            'data': 'YII_CSRF_TOKEN=' + $('input[name="YII_CSRF_TOKEN"]').val()+"&status=" + userRate + "&" + type + "=" + classcoursId,
            'success': function(data) {
                 for (var i = 1; i <=userRate; i++) {
                    if (i == 1) {
                        var newId = array[1] - userRate;
                    }
                    var newhiltedId = newId + i;                    
                    $("#" + array[0] + '_' + newhiltedId).next('label').css('background', '#efc623');
                }
            },
            'cache': false
        });

    }

    function rateTotarinner(id, userType,userId) {
        var status = $("#" + id).val();
        array = id.split('_');
        jQuery.ajax({
            'type': 'POST',
            'url': "<?php echo Yii::app()->createUrl("ClassCourseTrainnerRate/trainerRate"); ?>",
            'data': 'YII_CSRF_TOKEN=' + $('input[name="YII_CSRF_TOKEN"]').val()+"&userId=" + userId + "&userType=" + userType + "&status=" + status,
            'success': function(data) {
                for (var i = 1; i <=status; i++) {
                    if (i == 1) {
                        var newId = array[1] - status;
                    }
                    var newhiltedId = newId + i;                    
                    $("#" + array[0] + '_' + newhiltedId).next('label').css('background', '#efc623');
                }

               
            },
            'cache': false
        });

    }



    function cancelQuery(id) {
        $("#" + id).hide("slow", function() {
        });
    }

</script>